package com.algrithom.dp;

import com.common.constants.NumberConstants;

/**
 *
 */
public class Solution7 {
    
    public static void main(String[] args){
        System.out.println("Jump flow num is: " + jumpFloor1(5));
        System.out.println("Jump flow num is: " + jumpFloor2(5));
    }
    
    private static int jumpFloor1(int n){
        if (n <= NumberConstants.TWO) {
            return n;
        } else {
            return jumpFloor1(n - 1) + jumpFloor1(n - 2);
        }
    }
    
    private static int jumpFloor2(int size){
        int[] array = new int[size];
        
        if (size > NumberConstants.THRESH_HOLD_ONE || size == 0) {
            return 1;
        }
        if (size <= NumberConstants.TWO) {
            return size;
        }
        
        array[0] = 1;
        array[1] = 2;
        for (int i = 0; i < size - NumberConstants.TWO; i++) {
            array[i + 2] = (array[i] + array[i + 1]) % NumberConstants.THRESH_HOLD_ONE;
        }
        return array[size - 1];
    }
}
